package co.wizardattack.model;

import java.io.IOException;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.opengl.texture.TextureManager;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import android.content.Context;

public class Fireball {

	/**
	 * Constantes
	 */
	private final String CONS_IMAGE_PATH = "images/";
	private final String CONS_IMAGE_FIREBALL = "fireball.png";
	private final int CONS_ATLAS_WIDTH = 1441;
	private final int CONS_ATLAS_HEIGTH = 143;
	private final int CONS_IMAGE_COLUMNS = 4;
	private final int CONS_IMAGE_ROWS = 1;

	/**
	 * Atributos
	 */
	private float posX = 300;
	private float posY = 243;
	private BitmapTextureAtlas atlasAnimatedFireball;
	private ITiledTextureRegion textureAnimatedFireball;
	private AnimatedSprite spriteAnimatedFireball;

	/**
	 * Constructor
	 */
	public Fireball() {

	}

	/**
	 * Metodos
	 */
	public void onCreateResourcesFireball(TextureManager textureManager,
			Context context) throws IOException {BitmapTextureAtlasTextureRegionFactory
				.setAssetBasePath(CONS_IMAGE_PATH);
		atlasAnimatedFireball = new BitmapTextureAtlas(textureManager,
				CONS_ATLAS_WIDTH, CONS_ATLAS_HEIGTH, TextureOptions.DEFAULT);
		textureAnimatedFireball = BitmapTextureAtlasTextureRegionFactory
				.createTiledFromAsset(atlasAnimatedFireball, context,
						CONS_IMAGE_FIREBALL, 0, 0, CONS_IMAGE_COLUMNS,
						CONS_IMAGE_ROWS);
		atlasAnimatedFireball.load();
	}

	public void onCreateSceneFireball(
			VertexBufferObjectManager vertexBufferObjectManager) {
		this.spriteAnimatedFireball = new AnimatedSprite(posX, posY,
				textureAnimatedFireball, vertexBufferObjectManager);
	}

	// ANIMACION

	void animated() {
		long[] duracionFrame = { 300, 100, 100, 150, 200, 200, 150, 100 };
		spriteAnimatedFireball.animate(duracionFrame, 0, 7, true);
	}


	// GETS AND SETS
	public float getPosX() {
		return spriteAnimatedFireball.getX();
	}

	public void setPosX(float posX) {
		spriteAnimatedFireball.setX(posX);
		this.posX = posX;
	}

	public float getPosY() {
		return spriteAnimatedFireball.getY();
	}

	public void setPosY(float posY) {
		spriteAnimatedFireball.setY(posY);
		this.posY = posY;
	}

	public AnimatedSprite getSpriteAnimatedFireball() {
		return spriteAnimatedFireball;
	}

}
